package com.ruoyi.web.controller.mes;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.web.domain.MesWarehousingDetail;
import com.ruoyi.web.domain.vo.MesUseDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MesUseInfo;
import com.ruoyi.web.service.IMesUseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸张领用单Controller
 *
 * @author wxt
 * @date 2024-01-17
 */
@Api("纸张领用单管理")
@RestController
@RequestMapping("/mes/use/info")
public class MesUseInfoController extends BaseController {
    @Autowired
    private IMesUseInfoService mesUseInfoService;

    /**
     * 查询纸张领用单列表
     */
    @ApiOperation("查询纸张领用单列表")
    @GetMapping("/list")
    public TableDataInfo list(MesUseInfo mesUseInfo) {
        startPage();
        List<MesUseInfo> list = mesUseInfoService.selectMesUseInfoList(mesUseInfo);
        return getDataTable(list);
    }

    /**
     * 导出纸张领用单列表
     */
    @ApiOperation("导出纸张领用单列表")
    @Log(title = "纸张领用单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesUseInfo mesUseInfo) {
        List<MesUseInfo> list = mesUseInfoService.selectMesUseInfoList(mesUseInfo);
        ExcelUtil<MesUseInfo> util = new ExcelUtil<MesUseInfo>(MesUseInfo.class);
        util.exportExcel(response, list, "纸张领用单数据");
    }


    /**
     * 导出纸张领用单列表
     */
    @ApiOperation("导出纸张领用明细单列表")
    @Log(title = "纸张领用明细单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDetail")
    public void exportDetail(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        MesUseInfo use = new MesUseInfo();
        use.setParams(params);
        List<MesUseDetailVo> list = mesUseInfoService.selectMesDetaillist(use);
        ExcelUtil<MesUseDetailVo> util = new ExcelUtil<MesUseDetailVo>(MesUseDetailVo.class);
        util.exportExcel(response, list, "纸张领用明细单数据");
    }

    /**
     * 获取纸张领用单详细信息
     */
    @ApiOperation("获取纸张领用单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mesUseInfoService.selectMesUseInfoById(id));
    }


    /**
     * 纸张领用明细查询
     */
    @ApiOperation("纸张领用明细查询")
    @PostMapping("/Detail")
    public TableDataInfo Detail(@RequestBody Map<String, Object> params) {
        //startPage();
        PageHelper.startPage((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        MesUseInfo use = new MesUseInfo();
        use.setParams(params);
        List<MesUseDetailVo> list = mesUseInfoService.selectMesDetaillist(use);
        return getDataTable(list);
    }

    @GetMapping("getUseDetail")
    public TableDataInfo getUseDetail(MesUseDetailVo useDetail) {
        startPage();
        List<MesUseDetailVo> list =mesUseInfoService.selectUseDetail(useDetail);
        return getDataTable(list);
    }


    /**
     * 新增纸张领用单
     */
    @ApiOperation("新增纸张领用单")
    @Log(title = "纸张领用单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesUseInfo mesUseInfo) {
        return toAjax(mesUseInfoService.insertMesUseInfo(mesUseInfo));
    }

    /**
     * 修改纸张领用单
     */
    @ApiOperation("修改纸张领用单")
    @Log(title = "纸张领用单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesUseInfo mesUseInfo) {
        return toAjax(mesUseInfoService.updateMesUseInfo(mesUseInfo));
    }

    /**
     * 删除纸张领用单
     */
    @ApiOperation("删除纸张领用单")
    @Log(title = "纸张领用单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mesUseInfoService.deleteMesUseInfoByIds(ids));
    }
}
